package top.malaoshi.ctrl;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.malaoshi.model.Result;
import top.malaoshi.service.ChangeSrvImpl;


import javax.annotation.Resource;

@RestController
public class ChangeCtrl {
    @Resource
    private ChangeSrvImpl srv;
    @RequestMapping("/update")
    public Result reg(String password, String newpassword, String phone) {
        Result mv=new Result();
        if(phone==null||"".equals(phone)){
            mv.setCode(11101);
            mv.setMsg("为什么不输入手机号？");
            return mv;
        }else if(password==null||"".equals(password)){
            mv.setCode(11102);
            mv.setMsg("你不输入密码还想改？当我们傻吗？");
            return mv;
        }else if(newpassword==null||"".equals(newpassword)){
            mv.setCode(11103);
            mv.setMsg("新密码你不输你想干啥？");
            return mv;
        }else {
            Result res = srv.change(password, phone, newpassword);
            if (res.getCode() == 0) {
                mv.setCode(11100);
                mv.setMsg("修改成功！");
                return mv;
            } else {
                mv.setCode(11104);
                mv.setMsg("没有这个手机号啊，你在想什么？");
                return mv;
            }
        }
    }
}